﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMSNet.Model.Models;
using WMSNet.Data.Repository;
using System.ServiceModel;
using WMSNet.Data;

namespace WMSNet.Core.Service
{
    public interface IItemDataService
    {
    }

    public class ItemDataService : IItemDataService
    {
        private readonly IItemDataRepository _itemDataRepository;
        private readonly IUnitOfWork _unitOfWork;

        public ItemDataService(IItemDataRepository itemDataRepository, IUnitOfWork unitOfWork)
        {
            this._itemDataRepository = itemDataRepository;
            this._unitOfWork = unitOfWork;
        }

        /// <summary>
        /// Checks the specified number for usage. if the
        /// number is available, a new ItemData is created and assigned to
        /// the client
        /// </summary>
        /// <param name="client"></param>
        /// <param name="number"></param>
        /// <returns></returns>
        public ItemData Create(Client client, string number)
        {
            if (client == null || number == null)
            {
                throw new FaultException("CreateItemData: Param == null");
            }

            ItemData itemData = new ItemData()
            {
                 Client= client,
                 Item_nr=number
            };

            //TODO:Log here
            _unitOfWork.Commit();

            return itemData;
        }

        /// <summary>
        /// Return client details using the specified client and itemNumber
        /// </summary>
        /// <param name="client"></param>
        /// <param name="itemNumber"></param>
        /// <returns></returns>
        public ItemData GetByItemNumber(Client client, string itemNumber)
        {
           return _itemDataRepository.Get(x => x.Item_nr == itemNumber &&
               x.Client.ClientID == client.ClientID);
        }

    }
}

